<template>
    <div>
        <div v-if="state.datatree.length == 0 && !state.addShowTtation">
            <p class="tree_title">
                <span class="fw700">分站以及测点配置</span>
            </p>
            <div style="text-align: center;">
                <img src="@/assets/images/nodata.png" alt="" />
                <p>暂无数据，请先配置分站</p>
                <el-button v-if="userStore.modify" plain type="info" @click="addstationBtn">新增分站</el-button>
            </div>
        </div>
    </div>
</template>

<script setup>
import useUserStore from "@/store/modules/user";
const userStore = useUserStore();
import axios from "@/utils/request"
defineProps({
    isActive: {
        type: Boolean,
        default: false,
    },
});

const emit = defineEmits();
const state = reactive({
    datatree: [],//树形数据
    addShowTtation: false,//新增分站弹框
    curTreeId: undefined,//当前树节点id
})
// 左侧树形上新增分站按钮点击事件
function addstationBtn() {

}
// 左侧树形搜索框
function treeSearchBlur(key) {
    getsider(state.treeSearch)
}
// 获取左边树形
function getsider(key) {
    let arr = []
    let children = []
    let children1 = []
    axios.get(`/station/sider`, {
        params: {
            key: key
        }
    }).then(res => {
        if (res.data.length > 0) {
            res.data.forEach(item => {
                if (item.pointInfos) {
                    children = item.pointInfos.map(item1 => {
                        return {
                            label: item1.pointId + '/' + item1.sensorName + '/' +
                                item1
                                    .pointPlaceName,
                            value: item1.pointId,
                            pointTypeName: item1.pointTypeName.substring(0, 2),
                            id: item1.pointId,
                        }
                    })
                } else {
                    children = []
                }
                if (item.controlPorts) {
                    children1 = item.controlPorts.map(item1 => {
                        return {
                            label: '',
                            value: item1.pointId,
                            controlPort: item1.controlPort,
                            id: item1.pointId,
                            place: item1.pointTypeName,
                            controlPortType: item1.controlPortType,
                            controlPortTypeName: item1.controlPortTypeName,
                            pointPlaceName: item1.pointPlaceName
                        }
                    })
                } else {
                    children1 = []
                }
                arr.push({
                    label: item.stationCode + '-' + item.stationPlaceName,
                    value: item.stationCode,
                    id: item.id,
                    type: 'fenzhan',
                    controlNum: item.controlNum,
                    totalNum: item.totalNum,
                    stationTypeId: item.stationTypeId,
                    children: [{
                        label: '测点',
                        value: 'nopoint',
                        id: 'nopoint',
                        children: children
                    }, {
                        label: '开出口',
                        value: 'noopen',
                        id: 'noopen',
                        children: children1
                    }]
                })
            })

            state.datatree = arr
        } else {
            state.datatree = res.data
        }
        nextTick(() => {
            if (state.curTreeId) {
                pointtree.value.setCurrentKey(state.curTreeId)
            }
        })
    })
}
getsider()

</script>

<style scoped></style>
